package com.house.java.action.news;

import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.house.java.biz.NewsBusiness;
import com.house.java.model.News;
import com.house.java.util.StringUtils;

public class NewsAction {

	public void queryNewsByCondition(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, UnsupportedEncodingException{
		request.setCharacterEncoding("utf-8");
		Integer locationCityCode = Integer.valueOf(request.getParameter("cityCode"));
		Integer locationProvinceCode = Integer.valueOf(request.getParameter("provinceCode"));
		Integer locationCountryCode = Integer.valueOf(request.getParameter("countryCode"));
		Integer houseCategory = Integer.valueOf(request.getParameter("houseCategory"));
		Integer currentPage = Integer.valueOf(request.getParameter("currentPage"));
		Integer pageSize = Integer.valueOf(request.getParameter("pageSize"));
		// 查询数据
		NewsBusiness biz = new NewsBusiness();
		List<News> list = biz.queryNews(locationCityCode, locationProvinceCode, locationCountryCode, currentPage, pageSize); 
		// 将list集合对象绑定到request区域中
		// 通过request.setAttribute(绑定名字，集合变量)；方法绑定
		request.setAttribute("news",list);
	}
	
	public void queryNewsById(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, UnsupportedEncodingException{
		request.setCharacterEncoding("utf-8");
		String idStr = request.getParameter("id");
		Long id = null;
		if(StringUtils.hasLength(idStr)){
			id = Long.valueOf(idStr);
		}
		// 查询数据
		NewsBusiness biz = new NewsBusiness();
		News news = biz.queryNewsById(id); 
		// 将list集合对象绑定到request区域中
		// 通过request.setAttribute(绑定名字，集合变量)；方法绑定
		request.setAttribute("news",news);
	}
	
	
	public void delete(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, UnsupportedEncodingException{
		request.setCharacterEncoding("utf-8");
		String idStr = request.getParameter("id");
		Long id = null;
		if(StringUtils.hasLength(idStr)){
			id = Long.valueOf(idStr);
		}
		// 查询数据
		NewsBusiness biz = new NewsBusiness();
		boolean result = biz.delete(id); 
		// 将list集合对象绑定到request区域中
		// 通过request.setAttribute(绑定名字，集合变量)；方法绑定
		request.setAttribute("news",result);
	}
}
